package com.itheima.health.mapper;

import com.itheima.health.pojo.OrderSetting;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.util.Date;
import java.util.List;

/**
 * @author spt
 * @description 预约设置DAO
 * @date 2019/9/29
 **/
@Mapper
public interface OrderSettingMapper {

    List<OrderSetting> getOrderSettingByDate(@Param("start") LocalDate start, @Param("end") LocalDate end);

    void insertBeatch(@Param("list") List<OrderSetting> cachedDataList);

    @Select("select count(*) from t_ordersetting where orderDate = #{date}")
    Integer selectCountByDate(Date date);

    void updateOrderSetting(OrderSetting build);

    @Select("select number - reservations from t_ordersetting where orderDate = #{orderDate}")
    Integer selectAvaildCountByDate(Date orderDate);

    @Update("update t_ordersetting set reservations = reservations + 1 where orderDate = #{orderDate}")
    void updateOrderAvaildCount(Date orderDate);
}
